package com.example.a22310.myapplication.ViewModel.Order;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.Order;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.OrderModel;
import com.example.a22310.myapplication.databinding.ActivityOrderBinding;

import java.util.List;

public class OrderViewModel implements ActivityLisenter<Order> {

    private ActivityOrderBinding binding;
    private AppCompatActivity activity;
    private int status=0;
    private int userid;


    public OrderViewModel(AppCompatActivity activity, ActivityOrderBinding binding, int userid,int status){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        this.status=status;
        binding.setOrder(this);
        OrderModel orderModel=new OrderModel();
        orderModel.orderlist(OrderViewModel.this,userid,status);

    }

    public void back(View view){
        activity.onBackPressed();
    }

    @Override
    public void onSuccess(Order order) {
        if(order.getCode()!=404){
            List<Order.OrderlistBean> orderlistBean =  order.getOrderlist();
            binding.recyclerViewOrder.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_order,
                    orderlistBean, BR.order);
            binding.recyclerViewOrder.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
    }
}

